#https://blog.csdn.net/weixin_42551465/article/details/80817552

#尝试刷访问量
#简述在登陆账号的情况下，在访问过一片文章后,访问量+1，无法通过再次访问来增加访问量
#但是不登陆的话可以无限增加访问量

# from selenium import webdriver
#
#
# def IncreaseViews():
#     #url = input('请输入需要访问的地址(并按空格再按回车)')
#     url = "https://www.jianshu.com/p/0cf216fd45b5"
#     #n = int(input('请输入要访问的次数'))
#     n=20000
#     browser = webdriver.Firefox()
#     for i in range(n):
#         browser.get(url)
#         browser.refresh()
#         print('成功访问{}次'.format(i+1))
#         i += 1
#     browser.close()
#
# IncreaseViews()


from selenium import webdriver
import time
import re
from pyquery import PyQuery as pq

def openurl(url):
    browser = webdriver.Firefox()
    browser.get("https://login.ces.tech/")
    # html = browser.page_source
    # data = str(pq(html))
    # print(data)
    time.sleep(5)
    #先执行登陆事件
    #设置账号
    browser.find_element_by_id("okta-signin-username").send_keys("280829500@qq.com")
    #设置密码
    browser.find_element_by_id("okta-signin-password").send_keys("Hyzlovezx52199")
    #执行登陆
    browser.find_element_by_id("okta-signin-submit").click()
    #等待5秒
    time.sleep(5)

    #跳转至界面
    browser.get(url)
    #等待5秒
    time.sleep(5)
    #开始
    while(1):
        #获取添加按钮
        datalist = browser.find_elements_by_class_name("agenda-btn-add")
        # count = len(datalist)
        if len(datalist) <= 0:
            loadmore = browser.find_element_by_class_name("schedule-events__load-more")
            if loadmore :
               loadmore.click()
               time.sleep(2)
            else:
                break
        else:
            print(len(datalist))
            for i in range(0, len(datalist)):
                print(i)
                datalist[i].click()
                time.sleep(4)
                browser.get(url)
                time.sleep(3)
            #
            time.sleep(6)
            browser.get(url)
            time.sleep(5)
    print("结束")



    #browser.find_element_by_class_name("schedule-events__load-more").click()
    #ces-btn--round agenda-btn-add

    #browser.find_element_by_class_name("agenda-btn-add").click()

    # browser.find_element_by_id("kw").send_keys("python")
    # browser.find_element_by_id("su").click()

    # dic = {}
    # re_rule = r'<button class="btn ces-btn ces-btn--round agenda-btn-add" data-id="505895"><i class="fa fa-plus"></i>Add to my agenda</button>'
    # datalist = re.findall(re_rule,data,re.S)
    # for i in range(0,len(datalist)):
    #     print(datalist[i])
    #     rule1 = r'<img src="/img/icon-lihao.png" data-v-6c26747a=""/>(.*?)<!----></span>'
    #     bullish = re.findall(rule1, datalist[i], re.S)
    #     if len(bullish) == 0:
    #         rule1 = r'<img src="/img/icon-likong.png" data-v-6c26747a=""/>(.*?)</span>'
    #         bullish = re.findall(rule1, datalist[i], re.S)
    #
    #     rule2 = r'<span class="stock-group-item-name" data-v-f97d9694="">(.*?)</span>'
    #     stock_name = re.findall(rule2, datalist[i], re.S)
    #
    #     if len(stock_name) > 0 and len(bullish) > 0:
    #         for c in range(0, len(stock_name)):
    #             dic[stock_name[c]] = bullish[0]
    #             print("正在爬取第", len(dic) + 1, "个请稍等.....")
    #
    # c = len(datalist)
    # if len(dic) < num:
    #     while (1):
    #         browser.find_element_by_class_name("home-news-footer").click()
    #         time.sleep(1)
    #         html = browser.page_source
    #         data = str(pq(html))
    #         datalist = re.findall(re_rule, data, re.S)
    #         for i in range(c, len(datalist)):
    #             rule3 = r'<img data-v-6c26747a="" src="/img/icon-lihao.png"/>(.*?)<!----></span>'
    #             bullish = re.findall(rule3, datalist[i], re.S)
    #             if len(bullish) == 0:
    #                 rule5 = r'<img data-v-6c26747a="" src="/img/icon-likong.png"/>(.*?)</span>'
    #                 bullish = re.findall(rule5, datalist[i], re.S)
    #
    #             rule4 = r'<span data-v-f97d9694="" class="stock-group-item-name">(.*?)</span>'
    #             stock_name = re.findall(rule4, datalist[i], re.S)
    #
    #             if len(stock_name) > 0 and len(bullish) > 0:
    #                 for c in range(0, len(stock_name)):
    #                     dic[stock_name[c]] = bullish[0]
    #
    #         c = len(datalist)
    #         if len(dic) > num:
    #             browser.quit()
    #             print("爬取完毕！！")
    #             break
    #
    #         print("正在爬取第", len(dic) + 1, "个请稍等.....")
    # else:
    #     browser.quit()
    #     print("爬取完毕！！")
    # return dic

#添加按钮
#<button class="btn ces-btn ces-btn--round agenda-btn-add" data-id="505895"><i class="fa fa-plus"></i>Add to my agenda</button>
#加载更多按钮
#<button class="btn schedule-events__load-more">Load More</button>

url='https://www.ces.tech/Schedule.aspx'
openurl(url)
#dict=openurl(url,3)
#print(dict)